#Initialize pygame

import sys
import os.path
import pickle

windows = sys.platform[:3].lower() == 'win'
mac = sys.platform[:6].lower() == 'darwin'

#Weird bug on Windows with finding pygame._view: importing manually seems to fix it
if windows:
   import pygame._view

import pygame
from pygame.locals import *

pygame.init()
pygame.font.init()

settingsfile = 'Settings.cfg'

#Global shared namespace

class EffectList(object):
   __slots__ = ('effects',)
   
   def __init__(self):
      self.effects = list()
   
   def add(self, effect):
      self.effects.append(effect)
   
   def empty(self):
      self.effects = list()
   
   def update(self):
      for i, effect in enumerate(self.effects):
         if effect.update():
            del self.effects[i]

game = None
player_ship = None #User_Ship

projectiles = pygame.sprite.Group()
friendly_ships = pygame.sprite.Group()
enemy_ships = pygame.sprite.Group()
shields = pygame.sprite.Group()
effect_sprites = pygame.sprite.Group()
HUD = pygame.sprite.Group()
powerups = pygame.sprite.Group()
UI = pygame.sprite.Group()

effects = EffectList()

powerup_dict = dict()
items = dict()
ships = dict()

action_queue = list()
messages = list()

pressed_buttons = list()

if os.path.exists(settingsfile):
   settings = pickle.load(open(settingsfile, 'r'))
else:
   settings = dict()

def savesettings():
   import Keys
   
   Keys.save()
   
   pickle.dump(settings, open(settingsfile, 'w'))
